package LC;

import java.util.Arrays;

/**
 * https://leetcode.com/problems/remove-element/description/
 * Given an array and a value, remove all instances of that value in place and return the new length.
 * Do not allocate extra space for another array, you must do this in place with constant memory.
 * The order of elements can be changed. It doesn't matter what you leave beyond the new length.
 * Example:
 * Given input array nums = [3,2,2,3], val = 3
 * Your function should return length = 2, with the first two elements of nums being 2.
 */
public class LC_027_RemoveElement_Array {
    public static void main(String[] args) {
        int[] a = {1, 4, 4, 4, 5, 5, 5, 6, 7, 8, 9};
        int k = 4;
        int n = Solution.removeElement(a, k);
        System.out.println(n);
    }

    static class Solution {
        static int removeElement(int[] nums, int val) {
            System.out.println(nums.length);
            int count = 0;
            for (int i = 0; i < nums.length; i++) {
                if (nums[i] != val) {
                    nums[count++] = nums[i];
                }
            }
            System.out.println(Arrays.toString(nums));
            System.out.println(nums.length);
            return count;
        }
    }
}
